package com.explorati.interview.interview.chapterfive;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class MyList implements Iterable<String>, Iterator<String> {

	private int loc = 0;
	private List<String> list = new ArrayList<String>();

	public void remove() {
		list.remove(loc);
	}

	public List<String> getList() {
		return list;
	}

	@Override
	public Iterator<String> iterator() {
		return this;
	}

	@Override
	public boolean hasNext() {
		return list.size() > loc;
	}

	@Override
	public String next() {
		return list.get(loc);
	}

	public static void main(String[] args) {
		MyList list = new MyList();
		list.getList().add("I");
		list.getList().add(" ");
		list.getList().add("love");
		list.getList().add(" ");
		list.getList().add("you");
		for (String s : list) {
			System.out.print(s);
		}
	}
}
